<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta name="description" content="What is an ocean, but mutiple of drops.">
<meta property="og:type" content="website">
<meta property="og:title" content="StrayBirds">
<meta property="og:url" content="https://straybirds.top/index.html">
<meta property="og:site_name" content="StrayBirds">
<meta property="og:description" content="What is an ocean, but mutiple of drops.">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="StrayBirds">
<meta name="twitter:description" content="What is an ocean, but mutiple of drops.">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://straybirds.top/">





  <title>StrayBirds</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?1c055ff4eb7f9e86cf845aeff86f38d5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">StrayBirds</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2020/03/03/vue-GET-http-example-com-null-404-Not-Found/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2020/03/03/vue-GET-http-example-com-null-404-Not-Found/" itemprop="url">vue GET http://example.com/null 404 (Not Found)</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-03T16:36:15+08:00">
                2020-03-03
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/03/03/vue-GET-http-example-com-null-404-Not-Found/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/03/03/vue-GET-http-example-com-null-404-Not-Found/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2020/03/03/vue-GET-http-example-com-null-404-Not-Found/" class="leancloud_visitors" data-flag-title="vue GET http://example.com/null 404 (Not Found)">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>出现请求 /null一般是图片地址为null导致的，需要在判断<code>img</code>标签的<code>src</code>属性和<code>backgroundImage</code>样式中的<code>url</code>是否为<code>null</code> 。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">    methods:&#123;</span><br><span class="line">        getThumbnail(item) &#123;</span><br><span class="line">            <span class="keyword">const</span> imageUrl = item.url_pic ? item.url_pic : <span class="string">""</span>;</span><br><span class="line">            <span class="keyword">return</span> &#123; <span class="attr">backgroundImage</span>: <span class="string">`url(<span class="subst">$&#123;imageUrl&#125;</span>)`</span> &#125;;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2020/03/02/自适应布局中保持元素的宽高比/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2020/03/02/自适应布局中保持元素的宽高比/" itemprop="url">自适应布局中保持元素的宽高比</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-02T17:02:30+08:00">
                2020-03-02
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/03/02/自适应布局中保持元素的宽高比/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/03/02/自适应布局中保持元素的宽高比/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2020/03/02/自适应布局中保持元素的宽高比/" class="leancloud_visitors" data-flag-title="自适应布局中保持元素的宽高比">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>只是用css就能达到效果，不设高度，使用<code>padding-top</code>或<code>padding-bottom</code>来撑开，它的值是基于元素的宽度的</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-class">.box</span>&#123;</span></span><br><span class="line"><span class="css">    <span class="selector-tag">width</span><span class="selector-pseudo">:20</span>%;</span></span><br><span class="line">    /* </span><br><span class="line"><span class="css">        <span class="selector-tag">padding-top</span><span class="selector-pseudo">:50</span>%意为元素宽度的50%</span></span><br><span class="line">        padding-bottom亦可 </span><br><span class="line">    */</span><br><span class="line"><span class="css">    <span class="selector-tag">padding-top</span><span class="selector-pseudo">:50</span>%; </span></span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"box"</span>&gt;</span><span class="tag">&lt;/<span class="name">box</span>&gt;</span></span><br></pre></td></tr></table></figure>


          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2020/02/04/GIT常用命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2020/02/04/GIT常用命令/" itemprop="url">GIT常用命令</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-02-04T14:14:20+08:00">
                2020-02-04
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/02/04/GIT常用命令/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/02/04/GIT常用命令/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2020/02/04/GIT常用命令/" class="leancloud_visitors" data-flag-title="GIT常用命令">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Git 全局设置:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;git username&quot;</span><br><span class="line">git config --global user.email &quot;git email&quot;</span><br></pre></td></tr></table></figure>

<p>创建 git 仓库:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">mkdir tests</span><br><span class="line">cd tests</span><br><span class="line">git init</span><br><span class="line">touch README.md</span><br><span class="line">git add README.md</span><br><span class="line">git commit -m &quot;first commit&quot;</span><br><span class="line">git remote add origin &lt;repo address&gt;</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<p>已有仓库?</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd existing_git_repo</span><br><span class="line">git remote add origin &lt;repo address&gt;</span><br><span class="line">git push -u origin master</span><br></pre></td></tr></table></figure>

<p>设置远程仓库地址</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote set-url origin &lt;repo new address&gt;</span><br></pre></td></tr></table></figure>


          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2020/01/19/Vue工程化思考/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2020/01/19/Vue工程化思考/" itemprop="url">Vue工程化思考</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-01-19T10:44:38+08:00">
                2020-01-19
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/01/19/Vue工程化思考/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/01/19/Vue工程化思考/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2020/01/19/Vue工程化思考/" class="leancloud_visitors" data-flag-title="Vue工程化思考">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>参考了开源项目<a href="https://github.com/ElemeFE/element" target="_blank" rel="noopener">element-ui</a>，<a href="https://github.com/PanJiaChen/vue-element-admin" target="_blank" rel="noopener">vue-element-admin</a>，并结合自己的实践整理的一个Vue工程化实践总结。</p>
<h2 id="开发"><a href="#开发" class="headerlink" title="开发"></a>开发</h2><h3 id="整合scss"><a href="#整合scss" class="headerlink" title="整合scss"></a>整合scss</h3><h3 id="远程开发"><a href="#远程开发" class="headerlink" title="远程开发"></a>远程开发</h3><p>有服务器的小伙伴可以尝试下。</p>
<h2 id="优化"><a href="#优化" class="headerlink" title="优化"></a>优化</h2><h3 id="Gzip压缩"><a href="#Gzip压缩" class="headerlink" title="Gzip压缩"></a>Gzip压缩</h3><h2 id="部署"><a href="#部署" class="headerlink" title="部署"></a>部署</h2><h3 id="Apache-Tomcat-配置vue-router-history模式"><a href="#Apache-Tomcat-配置vue-router-history模式" class="headerlink" title="Apache Tomcat 配置vue router history模式"></a>Apache Tomcat 配置vue router history模式</h3><p>在工程根目录下新建WEB-INF文件夹，并新建web.xml文件，文件内容如下。重启tomcat。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">web-app</span> <span class="attr">xmlns</span>=<span class="string">"http://java.sun.com/xml/ns/javaee"</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</span> <span class="attr">version</span>=<span class="string">"3.0"</span> <span class="attr">metadata-complete</span>=<span class="string">"true"</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="tag">&lt;<span class="name">display-name</span>&gt;</span>Your Project Name<span class="tag">&lt;/<span class="name">display-name</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">description</span>&gt;</span></span><br><span class="line">     Your Project Description</span><br><span class="line">  <span class="tag">&lt;/<span class="name">description</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">error-page</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">error-code</span>&gt;</span>404<span class="tag">&lt;/<span class="name">error-code</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">location</span>&gt;</span>/<span class="tag">&lt;/<span class="name">location</span>&gt;</span>  </span><br><span class="line">  <span class="tag">&lt;/<span class="name">error-page</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">web-app</span>&gt;</span></span><br></pre></td></tr></table></figure>


          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2020/01/19/前端工程包体积优化/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2020/01/19/前端工程包体积优化/" itemprop="url">前端工程包体积优化</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-01-19T10:04:14+08:00">
                2020-01-19
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/01/19/前端工程包体积优化/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/01/19/前端工程包体积优化/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2020/01/19/前端工程包体积优化/" class="leancloud_visitors" data-flag-title="前端工程包体积优化">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="常见踩坑"><a href="#常见踩坑" class="headerlink" title="常见踩坑"></a>常见踩坑</h3><h4 id="Vue组件中无法修改UI框架的样式"><a href="#Vue组件中无法修改UI框架的样式" class="headerlink" title="Vue组件中无法修改UI框架的样式"></a>Vue组件中无法修改UI框架的样式</h4><p>如果在Vue组件中使用了scoped，那么vue会给组件中的dom元素和css选择器添加一个hash属性来确保只作用于组件内部，会导致无法修改UI组件样式的情况。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"container"</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--使用iView的input组件--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">Input</span> /&gt;</span> </span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">scoped</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-class">.container</span> <span class="selector-tag">input</span> &#123;</span></span><br><span class="line">    background: black;</span><br><span class="line">&#125;</span><br><span class="line"><span class="xml"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span></span><br></pre></td></tr></table></figure>

<p>会被编译成如下：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">data-v-b15f2372</span> <span class="attr">class</span>=<span class="string">"container"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">data-v-b15f2372</span> <span class="attr">class</span>=<span class="string">"ivu-input-wrapper ivu-input-wrapper-default ivu-input-type"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"ivu-input-inner-container"</span> <span class="attr">style</span>=<span class="string">""</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">i</span> <span class="attr">class</span>=<span class="string">"ivu-icon ivu-icon-ios-loading ivu-load-loop ivu-input-icon ivu-input-icon-validate"</span>&gt;</span><span class="tag">&lt;/<span class="name">i</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">input</span> <span class="attr">autocomplete</span>=<span class="string">"off"</span> <span class="attr">spellcheck</span>=<span class="string">"false"</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">placeholder</span>=<span class="string">""</span> <span class="attr">class</span>=<span class="string">"ivu-input ivu-input-default"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-class">.container</span> <span class="selector-tag">input</span><span class="selector-attr">[data-v-b15f2372]</span> &#123;</span></span><br><span class="line">    color: red;</span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>可以看到在父子组件嵌套时，只有子组件的根元素会被打上组件属性<code>data-v-b15f2372</code>，而组件内部的input则没有，这就会导致编译后的css选择器无法命中input元素。<br>解决方法：</p>
<ol>
<li>不使用scoped。</li>
<li>将应用于第三方组件库的样式写在全局style中，比如单独写一个global.scss，在mian.js中import。</li>
</ol>
<h3 id="体积优化"><a href="#体积优化" class="headerlink" title="体积优化"></a>体积优化</h3><h4 id="模块化："><a href="#模块化：" class="headerlink" title="模块化："></a>模块化：</h4><p>直接引用模块而不是整个包，可以减小打包后的工程体积。举例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// bad</span></span><br><span class="line"><span class="keyword">import</span> debounce <span class="keyword">from</span> <span class="string">"lodash/debounce"</span>;</span><br><span class="line"><span class="comment">// good</span></span><br><span class="line"><span class="keyword">import</span> &#123; debounce &#125; <span class="keyword">from</span> <span class="string">"lodash"</span>;</span><br></pre></td></tr></table></figure>

<h4 id="图片："><a href="#图片：" class="headerlink" title="图片："></a>图片：</h4><p>尽可能使用品质为8的jpg格式代替png格式图片，尤其是较大的背景图，图片大小可以减少一半以上。</p>
<h4 id="字体："><a href="#字体：" class="headerlink" title="字体："></a>字体：</h4><p>优化字体大小，可以使用：<a href="https://ecomfe.github.io/fontmin/#banner" target="_blank" rel="noopener">https://ecomfe.github.io/fontmin/#banner</a><br>比如项目中只用到一款字体的字母和数字，可以使用上述工具只保留使用字，将其他字体内容去掉，减小体积。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2019/12/27/php安装zlib扩展/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/12/27/php安装zlib扩展/" itemprop="url">php安装zlib扩展</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-27T22:43:00+08:00">
                2019-12-27
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/12/27/php安装zlib扩展/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/12/27/php安装zlib扩展/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/12/27/php安装zlib扩展/" class="leancloud_visitors" data-flag-title="php安装zlib扩展">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>帮朋友搭个企业站，求快速方便就用了成熟的wordpress，在登录和安装插件的时候都会遇到报错<code>Fatal error: Uncaught Error: Call to undefined function gzinflate() in XXX</code>,是因为缺少zlib扩展。修复步骤整理如下：</p>
<blockquote>
<p>php版本：7.2.26</p>
</blockquote>
<p>找到php安装的文件夹，进入下面的ext/lib</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/src/php-7.2.26/ext/lib</span><br></pre></td></tr></table></figure>

<p>复制一份config文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp config0.m2 config.m4</span><br></pre></td></tr></table></figure>

<p>执行<code>phplize</code>，如果提示无此命令可以安装<code>yum install php-devel</code>再试<br>这样就生成了configure文件<br>接下来先找到php-config和zlib.h的位置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">find / -name <span class="string">'php-config'</span></span><br><span class="line">find / -name <span class="string">'zlib.h'</span></span><br></pre></td></tr></table></figure>

<p>执行configure，注意后面的zlib文件夹不用写全</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./configure --with-php-config=/usr/<span class="built_in">local</span>/php-fpm/bin/php-config --with-zlib=/usr</span><br></pre></td></tr></table></figure>

<p>执行编译</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make &amp;&amp; make install</span><br></pre></td></tr></table></figure>

<p>修改php.ini,在文件中加入<code>extension=zlib.so</code>,然后将zlib.output_compression和zlib.output_compression_level分别为On和6</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">extension</span>=zlib.so</span><br><span class="line"><span class="attr">zlib.output_compression</span> = <span class="literal">On</span></span><br><span class="line"><span class="attr">zlib.output_compression_level</span> = <span class="number">6</span></span><br></pre></td></tr></table></figure>

<p>重启php</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">service php-fpm restart</span><br></pre></td></tr></table></figure>

<p>重启后查看phpinfo，就能看到zlib安装完成了。<br><img src="/uploads/2019/12/phpinfo.png" alt="PHPINFO" title="phpinfo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2019/12/04/spring-boot 读取配置文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/12/04/spring-boot 读取配置文件/" itemprop="url">spring-boot 读取配置文件</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-04T10:28:00+08:00">
                2019-12-04
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/12/04/spring-boot 读取配置文件/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/12/04/spring-boot 读取配置文件/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/12/04/spring-boot 读取配置文件/" class="leancloud_visitors" data-flag-title="spring-boot 读取配置文件">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><code>spring-boot</code>的配置文件一般放在<code>.properties</code>或<code>.yml</code>文件，配置和读取的方式分别如下：</p>
<h3 id="YML"><a href="#YML" class="headerlink" title="YML"></a>YML</h3><p>yml使用空格来划分层次，不能用tab。几个空格没关系，关键是要有层级关系，同层级的空格要保持一致。</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">person:</span></span><br><span class="line"><span class="attr">  lastName:</span> <span class="string">张三</span></span><br><span class="line"><span class="attr">  age:</span> <span class="number">18</span></span><br><span class="line"><span class="attr">  boss:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">  birth:</span> <span class="number">2019</span><span class="string">/02/02</span></span><br><span class="line"><span class="attr">  maps:</span> <span class="string">&#123;k1:v1,k2:v2&#125;</span></span><br><span class="line"><span class="attr">  lists:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">lisi</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">zhaosi</span></span><br><span class="line"><span class="attr">  dog:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">tom</span></span><br><span class="line"><span class="attr">    age:</span> <span class="number">2</span></span><br></pre></td></tr></table></figure>

<p>读取配置，首先使用<code>@Component</code>注解将类加入到容器中，然后使用<code>@ConfigurationProperties</code>注解将配置应该到Bean上。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@ConfigurationProperties</span>(prefix = <span class="string">"person"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Person</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String lastName;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="keyword">private</span> Boolean boss;</span><br><span class="line">    <span class="keyword">private</span> Date birth;</span><br><span class="line">    <span class="keyword">private</span> Map&lt;String,Object&gt; maps;</span><br><span class="line">    <span class="keyword">private</span> List&lt;Object&gt; lists;</span><br><span class="line">    <span class="keyword">private</span> Dog dog;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="PROPERTIES"><a href="#PROPERTIES" class="headerlink" title="PROPERTIES"></a>PROPERTIES</h3><p>properties文件配置方式如下。读取配置方式和上面一样。</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">server.port</span>=<span class="string">8081</span></span><br><span class="line"><span class="meta">person.last-name</span>=<span class="string">张三</span></span><br><span class="line"><span class="meta">person.age</span>=<span class="string">18</span></span><br><span class="line"><span class="meta">person.birth</span>=<span class="string">2017/12/15</span></span><br><span class="line"><span class="meta">person.boss</span>=<span class="string">false</span></span><br><span class="line"><span class="meta">person.maps.k1</span>=<span class="string">v1</span></span><br><span class="line"><span class="meta">person.maps.k2</span>=<span class="string">v2</span></span><br><span class="line"><span class="meta">person.lists</span>=<span class="string">a,b,c</span></span><br><span class="line"><span class="meta">person.dog.name</span>=<span class="string">dog</span></span><br><span class="line"><span class="meta">person.dog.age</span>=<span class="string">9</span></span><br></pre></td></tr></table></figure>

<p>在IDEA中，读取properties文件的中文时还需要配置一下文件编码，如下图：<br><img src="/uploads/2019/12/idea-file-encoding.png" alt="IDEA设置文件编码" title="IDEA设置文件编码"></p>
<h3 id="Value"><a href="#Value" class="headerlink" title="@Value"></a>@Value</h3><h3 id="ConfigurationProperties-与-Value的区别"><a href="#ConfigurationProperties-与-Value的区别" class="headerlink" title="@ConfigurationProperties 与 @Value的区别"></a>@ConfigurationProperties 与 @Value的区别</h3><table>
<thead>
<tr>
<th>Feature</th>
<th>@ConfigurationProperties</th>
<th>@value</th>
</tr>
</thead>
<tbody><tr>
<td>批量绑定</td>
<td>支持</td>
<td>不支持</td>
</tr>
<tr>
<td>松散语法绑定（lastName 写成 last-name）</td>
<td>支持</td>
<td>不支持</td>
</tr>
<tr>
<td>SpEl表达式（#{2*3}）</td>
<td>不支持</td>
<td>支持</td>
</tr>
<tr>
<td>JSR303数据校验</td>
<td>支持</td>
<td>不支持</td>
</tr>
<tr>
<td>复杂类型封装</td>
<td>支持</td>
<td>不支持</td>
</tr>
</tbody></table>
<p>校验方法如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Validated</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Person</span> </span>&#123;</span><br><span class="line">  <span class="meta">@Email</span></span><br><span class="line">  <span class="keyword">private</span> String email</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="读取不同的配置文件"><a href="#读取不同的配置文件" class="headerlink" title="读取不同的配置文件"></a>读取不同的配置文件</h2><p>如果配置内容比较多，都放在同一个配置文件下就会显得杂乱，不利于管理，我们可以将某些配置归类，放在不同的配置文件中。比如有这样一个person.properties文件：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">person.last-name</span>=<span class="string">LiSi</span></span><br><span class="line"><span class="meta">person.age</span>=<span class="string">18</span></span><br><span class="line"><span class="meta">person.birth</span>=<span class="string">2017/12/15</span></span><br><span class="line"><span class="meta">person.boss</span>=<span class="string">false</span></span><br><span class="line"><span class="meta">person.maps.k1</span>=<span class="string">v1</span></span><br><span class="line"><span class="meta">person.maps.k2</span>=<span class="string">v2</span></span><br><span class="line"><span class="meta">person.lists</span>=<span class="string">a,b,c</span></span><br><span class="line"><span class="meta">person.dog.name</span>=<span class="string">dog</span></span><br><span class="line"><span class="meta">person.dog.age</span>=<span class="string">9</span></span><br></pre></td></tr></table></figure>

<p>我们可以使用<code>@PropertySource</code>来获取它：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@PropertySource</span>(value = &#123;<span class="string">"classpath:person.properties"</span>&#125;)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Person</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String lastName;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="keyword">private</span> Boolean boss;</span><br><span class="line">    <span class="keyword">private</span> Date birth;</span><br><span class="line">    <span class="keyword">private</span> Map&lt;String,Object&gt; maps;</span><br><span class="line">    <span class="keyword">private</span> List&lt;Object&gt; lists;</span><br><span class="line">    <span class="keyword">private</span> Dog dog;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2019/11/27/sass常用语法整理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/27/sass常用语法整理/" itemprop="url">sass常用语法整理</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-27T10:21:25+08:00">
                2019-11-27
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/11/27/sass常用语法整理/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/11/27/sass常用语法整理/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/11/27/sass常用语法整理/" class="leancloud_visitors" data-flag-title="sass常用语法整理">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>体验一把css的模块化。首先从scss语法开始。</p>
<h4 id="声明变量与默认变量。"><a href="#声明变量与默认变量。" class="headerlink" title="声明变量与默认变量。"></a>声明变量与默认变量。</h4><p>默认变量可以被重新赋值。</p>
<blockquote>
<p>如果用户在局部文件中导入了变量,但是又在文件中重新声明了变量,则局部文件中的变量将会失效。</p>
</blockquote>
<figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$primary-color</span>: red;</span><br><span class="line"><span class="variable">$primary-color</span>: red !default;</span><br></pre></td></tr></table></figure>

<h4 id="导入文件"><a href="#导入文件" class="headerlink" title="导入文件"></a>导入文件</h4><ol>
<li><h5 id="嵌套导入"><a href="#嵌套导入" class="headerlink" title="嵌套导入"></a>嵌套导入</h5><p> css的import会在使用的时候再去下载引入的文件,而sass则会把import的内容编译到同一个css文件中.</p>
</li>
<li><h5 id="局部文件"><a href="#局部文件" class="headerlink" title="局部文件"></a>局部文件</h5><p> 专门为<code>@import</code>使用的文件称为局部文件,局部文件的文件名以下划线开头.</p>
</li>
</ol>
<h4 id="注释"><a href="#注释" class="headerlink" title="注释"></a>注释</h4><h4 id="继承"><a href="#继承" class="headerlink" title="继承"></a>继承</h4><figure class="highlight scss"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.error</span>&#123;</span><br><span class="line">    <span class="attribute">color</span>:red;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.text</span>&#123;</span><br><span class="line">    @<span class="keyword">extend</span>: .error;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上述语法可以理解为将<code>class=&quot;text&quot;</code>的样式改成<code>class=&quot;text error&quot;</code>,继承是基于语义化而不是基于属性的,这是与混合的区别,混合是基于属性的.<br>继承的重复属性是基于css权重生效的.<br>不要在后代选择器中使用继承,容易导致选择器数量失控</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2019/09/23/了解mapbox表达式/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/23/了解mapbox表达式/" itemprop="url">认识mapbox表达式（expression）</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-23T19:55:43+08:00">
                2019-09-23
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mapbox/" itemprop="url" rel="index">
                    <span itemprop="name">mapbox</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/09/23/了解mapbox表达式/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/09/23/了解mapbox表达式/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/09/23/了解mapbox表达式/" class="leancloud_visitors" data-flag-title="认识mapbox表达式（expression）">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>本文通过分析mapbox官网几个表达式示例，对初次阅读的疑难点进行辅助说明，来认识表达式。<br>合理使用表达式可以优化代码和图层结构，减少图层数量，优化地图性能。</p>
<p>在图层的<code>layout property</code>, <code>paint property</code>和<code>filter</code>属性设置上可以使用表达式。表达式是定义了使用下述运算符的公式。mapbox提供的表达式运算符集包括：</p>
<ul>
<li>用于对数值执行算术运算和其他运算的数学运算符</li>
<li>用于操纵布尔值和进行条件决策的逻辑运算符</li>
<li>用于操纵字符串的字符串运算符</li>
<li>数据操作员，提供对源功能属性的访问</li>
<li>摄像机操作员，提供对定义当前地图视图的参数的访问</li>
</ul>
<p>了解表达式首先要清除表达式的结构，它的形式是一个JSON数组。数组的第一个元素是表达式名称，后续元素都是表达式的参数。每个参数都是文字值（字符串，数字，布尔值或<code>null</code>）或其他表达式数组。也就是说，表达式里可以嵌套其他的表达式。</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[expression_name, argument_0, argument_1, ...]</span><br></pre></td></tr></table></figure>

<h4 id="数据表达式（Data-Expression）"><a href="#数据表达式（Data-Expression）" class="headerlink" title="数据表达式（Data Expression）"></a>数据表达式（Data Expression）</h4><p>数据表达式可以使用以下操作来获取数据的属性并用来确定外观:<code>get</code>,<code>has</code>,<code>id</code>,<code>geomerty-type</code>,<code>properties</code>,<code>feature-state</code>。</p>
<p>首先来了解下上述表达式类型：</p>
<ul>
<li><p><code>get</code><br>get会从当前feature的prperties中检索给定的属性值并返回，如果在第二个参数中提供了一个对象，则从该对象中检索属性值。<br>如果给了一个不存在的属性值，则返回null</p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"get"</span>, string]: value</span><br><span class="line">[<span class="string">"get"</span>, string, object]: value</span><br><span class="line"></span><br><span class="line">[<span class="string">"get"</span>, <span class="string">"id"</span>] <span class="comment">// 当前数据中的id属性值</span></span><br><span class="line">[<span class="string">"get"</span>, <span class="string">"id"</span>, &#123;<span class="attr">id</span>: <span class="number">3</span>&#125;] <span class="comment">// 3</span></span><br></pre></td></tr></table></figure>
</li>
<li><p><code>has</code><br> 检测当前feature属性中是否存在一个属性值。如果提供了一个对象作为第二个参数，则检测该对象。  </p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"has"</span>, string]: boolean</span><br><span class="line">[<span class="string">"has"</span>, string, object]: boolean</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>id</code><br> 获取当前feature的id（如果有的话） </p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"id"</span>]: value</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>geomerty-type</code><br> 获取当前数据的geometry类型，返回值有： Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon</p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"geometry-type"</span>]: string</span><br></pre></td></tr></table></figure>
</li>
<li><p><code>properties</code><br> 直接获取当前feature的properties对象。</p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"properties"</span>]: object</span><br></pre></td></tr></table></figure>

<p> 一般情况下，使用<code>[&quot;get&quot;, &quot;property_name&quot;]</code>更合适</p>
</li>
<li><p><code>feature-state</code><br> 检索当前feature state的属性值，如果属性不存在，返回null<br> feature state不是数据的一部分，而且必须通过手动添加的。可以理解为feature的状态管理器。<br> feature通过id来分别，id必须是整数或可以转换为整数的字符串。也就是说，想使用feature state，必须在数据源中带有符合上述要求的id字段。<br> 可以直接看官方的<a href="https://docs.mapbox.com/mapbox-gl-js/example/hover-styles/" target="_blank" rel="noopener">使用示例</a></p>
</li>
</ul>
<p>接下来看官方示例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"circle-color"</span>: [</span><br><span class="line">        <span class="string">"rgb"</span>,</span><br><span class="line">        <span class="comment">// red is higher when feature.properties.temperature is higher</span></span><br><span class="line">        [<span class="string">"get"</span>, <span class="string">"temperature"</span>],</span><br><span class="line">        <span class="comment">// green is always zero</span></span><br><span class="line">        <span class="number">0</span>,</span><br><span class="line">        <span class="comment">// blue is higher when feature.properties.temperature is lower</span></span><br><span class="line">        [<span class="string">"-"</span>, <span class="number">100</span>, [<span class="string">"get"</span>, <span class="string">"temperature"</span>]]  <span class="comment">//b 使用负号，</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上例中，<code>rgb</code>是<a href="https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-rgb" target="_blank" rel="noopener">mapbox</a>定义的一个样式表达式。摘录官方声明如下图：<br><img src="/uploads/2019/09/mapbox-expression-rgb.png" alt="rgb表达式" title="rbg表达式"></p>
<ol>
<li><code>get</code>是最常见的表达式之一，直接获取geojson数据中properties属性的值</li>
<li>“-“是一个<a href="https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-math" target="_blank" rel="noopener">数学表达式</a>, 接收两个参数，获取第一个参数减去第二个参数的值，如果只有一个参数，则获取 0-参数 的值：<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"-"</span>, <span class="number">100</span>, <span class="number">70</span>]  <span class="comment">// 30</span></span><br><span class="line">[<span class="string">"-"</span>, <span class="number">30</span>]       <span class="comment">// -30</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<p><strong>某些layout和paint属性尚不支持数据表达式，某个样式是否支持需要看<code>Style Specification</code>文档中改样式下<code>data-driven styling</code>说明</strong></p>
<h4 id="相机表达式（Camera-expressions）"><a href="#相机表达式（Camera-expressions）" class="headerlink" title="相机表达式（Camera expressions）"></a>相机表达式（Camera expressions）</h4><p>从名字就能看出来，相机表达式跟地图的相机视角有关。它是使用<code>zoom</code>操作的表达式，允许图层外观随地图的缩放级别而变化。可以用来控制数据密度和深度的外观样式。<br>看官方示例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"circle-radius"</span>: [</span><br><span class="line">        <span class="string">"interpolate"</span>, [<span class="string">"linear"</span>], [<span class="string">"zoom"</span>],</span><br><span class="line">        <span class="comment">// zoom is 5 (or less) -&gt; circle radius will be 1px</span></span><br><span class="line">        <span class="number">5</span>, <span class="number">1</span>,</span><br><span class="line">        <span class="comment">// zoom is 10 (or greater) -&gt; circle radius will be 5px</span></span><br><span class="line">        <span class="number">10</span>, <span class="number">5</span></span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>先来了接下<code>interpolate</code>：<br>interpolate通过在输入和输出值之间进行插值，产生连续/平滑的结果。输入值可以是任何数值表达式，停止输入值必须时严格按照升序排列的数字。输出类型则必须是<code>number</code> <code>array&lt;Number&gt;</code> <code>color</code>。<br>插值类型：</p>
<ul>
<li><code>[&quot;linear&quot;]</code>：在一对停止之间线性插值，小于和略大于输入。</li>
<li><code>[&quot;exponential&quot;, base]</code>：在停靠点之间以指数方式插值，小于和大于输入。base控制输出增加的速率：较高的值使输出增加到更高的范围。当值接近1时，输出线性增加。</li>
<li><code>[&quot;cubic-bezier&quot;, x1, y1, x2, y2]</code>：使用给定控制点定义的三次贝塞尔曲线进行插值。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">"interpolate"</span>,</span><br><span class="line">    interpolation: [<span class="string">"linear"</span>] | [<span class="string">"exponential"</span>, base] | [<span class="string">"cubic-bezier"</span>, x1, y1, x2, y2 ],</span><br><span class="line">    input: number,</span><br><span class="line">    stop_input_1: number, <span class="attr">stop_output_1</span>: OutputType,</span><br><span class="line">    stop_input_n: number, <span class="attr">stop_output_n</span>: OutputType, ...</span><br><span class="line">]: OutputType (number, array&lt;number&gt;, or Color)</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">    <span class="string">"interpolate"</span>, [<span class="string">"linear"</span>], [<span class="string">"zoom"</span>],</span><br><span class="line">    <span class="comment">// zoom is 5 (or less) -&gt; circle radius will be 1px</span></span><br><span class="line">    <span class="number">5</span>, <span class="number">1</span>,</span><br><span class="line">    <span class="comment">// zoom is 10 (or greater) -&gt; circle radius will be 5px</span></span><br><span class="line">    <span class="number">10</span>, <span class="number">5</span></span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<p>再回看上面的例子，在这种情况下，表达式表示当缩放级别为5或更低时，圆半径应为1像素，当缩放为10或更高时，圆半径应为5像素。 在两者之间，半径将在1到5个像素之间进行线性插值。</p>
<p>相机表达式可以在任何使用表达式的地方使用。但是当它用作<code>layout property</code> 和 <code>paint property</code>时，必须采取以下形式：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[ <span class="string">"interpolate"</span>, interpolation, [<span class="string">"zoom"</span>], ... ]</span><br><span class="line"></span><br><span class="line">[ <span class="string">"step"</span>, [<span class="string">"zoom"</span>], ... ]</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">    <span class="string">"let"</span>,</span><br><span class="line">    ... variable bindings...,</span><br><span class="line">    [ <span class="string">"interpolate"</span>, interpolation, [<span class="string">"zoom"</span>], ... ]</span><br><span class="line">]</span><br><span class="line"></span><br><span class="line">[</span><br><span class="line">    <span class="string">"let"</span>,</span><br><span class="line">    ... variable bindings...,</span><br><span class="line">    [ <span class="string">"step"</span>, [<span class="string">"zoom"</span>], ... ]</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<blockquote>
<p>mapbox 表达式官方文档<a href="https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions" target="_blank" rel="noopener">https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions</a></p>
</blockquote>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://straybirds.top/2019/09/11/hexo建站记录/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="stray_brid_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="StrayBirds">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/09/11/hexo建站记录/" itemprop="url">hexo建站记录</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-11T20:56:38+08:00">
                2019-09-11
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/hexo博客/" itemprop="url" rel="index">
                    <span itemprop="name">hexo博客</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/09/11/hexo建站记录/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/09/11/hexo建站记录/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/09/11/hexo建站记录/" class="leancloud_visitors" data-flag-title="hexo建站记录">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="HEXO配置"><a href="#HEXO配置" class="headerlink" title="HEXO配置"></a>HEXO配置</h2><ul>
<li><p>安装hexo</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo -g</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建heox博客</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo init &lt;blog name&gt;</span><br><span class="line"><span class="built_in">cd</span> &lt;blog name&gt;</span><br><span class="line">npm i</span><br></pre></td></tr></table></figure>
</li>
<li><p>装完依赖后执行<code>hexo server</code>即可本地预览了</p>
</li>
</ul>
<h4 id="添加文章"><a href="#添加文章" class="headerlink" title="添加文章"></a>添加文章</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new hexo建站记录</span><br></pre></td></tr></table></figure>

<h4 id="添加文章分类"><a href="#添加文章分类" class="headerlink" title="添加文章分类"></a>添加文章分类</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new page categories</span><br></pre></td></tr></table></figure>

<p>此时，在<code>/source/categories/index.md</code>中修改type为 <code>categories</code>，然后就可以在文章中添加分类了：<br> <figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: hexo建站记录</span><br><span class="line">date: 2019-09-11 20:56:38</span><br><span class="line">categories: hexo博客</span><br><span class="line">tags: </span><br><span class="line"><span class="bullet"> - </span>hexo博客</span><br><span class="line"><span class="bullet"> - </span>hexo</span><br><span class="line">---</span><br></pre></td></tr></table></figure></p>
<h4 id="添加文章标签"><a href="#添加文章标签" class="headerlink" title="添加文章标签"></a>添加文章标签</h4><p>步骤与添加分类几乎一样:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo new page tags</span><br></pre></td></tr></table></figure>

<p>此时，在<code>/source/tags/index.md</code>中修改type为 <code>tags</code>，然后就可以在文章中添加标签了：</p>
 <figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: hexo建站记录</span><br><span class="line">date: 2019-09-11 20:56:38</span><br><span class="line">tags: </span><br><span class="line"><span class="bullet"> - </span>hexo博客</span><br><span class="line"><span class="bullet"> - </span>hexo</span><br><span class="line">---</span><br></pre></td></tr></table></figure>

<h4 id="自动部署"><a href="#自动部署" class="headerlink" title="自动部署"></a>自动部署</h4><p>需要先安装依赖包：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>

<p><code>/_config.yml</code></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line"><span class="attr">  type:</span> <span class="string">git</span></span><br><span class="line"><span class="attr">  repo:</span> <span class="string">git@github.com:username/username.github.io.git</span></span><br><span class="line"><span class="attr">  branch:</span> <span class="string">master</span></span><br></pre></td></tr></table></figure>

<h4 id="安装hexo主题："><a href="#安装hexo主题：" class="headerlink" title="安装hexo主题："></a>安装hexo主题：</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/theme-next/hexo-theme-next themes/next</span><br></pre></td></tr></table></figure>

<p>在<code>_config.yml</code>中修改配置</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">theme:</span> <span class="string">next</span></span><br></pre></td></tr></table></figure>

<h4 id="自定义域名"><a href="#自定义域名" class="headerlink" title="自定义域名"></a>自定义域名</h4><ul>
<li>在<code>username.github.io</code>仓库的设置中，设置<code>Custom domain</code></li>
<li>在<code>username.github.io</code>仓库中新建一个CNAME文件，文件内容是你的域名<blockquote>
<p>为避免每次更新都需要重复创建文件，可以安装npm包<code>npm i hexo-generator-cname -S</code></p>
</blockquote>
</li>
<li>在DNS解析服务器上，配置解析规则，如下图所示：<br> <img src="/uploads/2019/09/dns-cname.png" alt="CNAME" title="记录类型：CNAME"><br> <img src="/uploads/2019/09/dns-a.png" alt="A" title="记录类型：A "><br>  IP需要手动<code>ping github.io</code>查看</li>
</ul>
<h2 id="Next主题配置"><a href="#Next主题配置" class="headerlink" title="Next主题配置"></a>Next主题配置</h2><h4 id="配置文章观看次数"><a href="#配置文章观看次数" class="headerlink" title="配置文章观看次数"></a>配置文章观看次数</h4><ul>
<li>注册<a href="https://leancloud.cn" target="_blank" rel="noopener">leancloud</a>, 并新建应用</li>
<li>新建Class: Counter<br><img src="/uploads/2019/09/leancloud-class.png" alt="新建好的Counter Class"></li>
<li>在 设置 -&gt; 安全中心中，设置安全域名。设置后，只有安全域名可以发送请求。<br><img src="/uploads/2019/09/leancloud-web-security.png" alt="设置安全域名"> </li>
<li>在 设置 -&gt; 应用 Key 中找到appid和appkey， 并在next的 <code>_config.yml</code>中配置<br><img src="/uploads/2019/09/leancloud-appid.png" alt="应用 Key"> <figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">valine:</span></span><br><span class="line"><span class="attr">  enable:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  appid:</span>  <span class="string">your</span> <span class="string">leancloud</span> <span class="string">appid</span></span><br><span class="line"><span class="attr">  appkey:</span>  <span class="string">your</span> <span class="string">leancloud</span> <span class="string">appkey</span></span><br></pre></td></tr></table></figure>

</li>
</ul>
<h4 id="配置valine"><a href="#配置valine" class="headerlink" title="配置valine"></a>配置valine</h4><p>在next的 <code>_config.yml</code>中同样配置leancloud的appid和appkey：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">leancloud_visitors:</span></span><br><span class="line"><span class="attr">  enable:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">  app_id:</span> <span class="string">your</span> <span class="string">leancloud</span> <span class="string">appid</span></span><br><span class="line"><span class="attr">  app_key:</span> <span class="string">your</span> <span class="string">leancloud</span> <span class="string">appkey</span></span><br></pre></td></tr></table></figure>

<h4 id="配置valine-CDN"><a href="#配置valine-CDN" class="headerlink" title="配置valine CDN"></a>配置valine CDN</h4><p>网上查询到的在next的_config.yml中配置cdn的方式已经过时，采用直接在 <code>/themes/next/layout/_third-party/comments/valine.swig</code>中替换引用js的地址的方法：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://cdn.jsdelivr.net/npm/valine@1.3.4/dist/Valine.min.js</span><br></pre></td></tr></table></figure>


          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/avatar.jpg" alt="stray_brid_">
            
              <p class="site-author-name" itemprop="name">stray_brid_</p>
              <p class="site-description motion-element" itemprop="description">What is an ocean, but mutiple of drops.</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">12</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">stray_brid_</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine@1.3.4/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: true,
        notify: false,
        appId: '8g39VF5cW0SljcelPGGyN4jm-gzGzoHsz',
        appKey: 'pKPp2FxqhUAUBIPsRabgUW5M',
        placeholder: 'Just go go',
        avatar:'robohash',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("8g39VF5cW0SljcelPGGyN4jm-gzGzoHsz", "pKPp2FxqhUAUBIPsRabgUW5M");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

</body>
</html>
